<?php
// +----------------------------------------------------------------------
// | SparkShop 坚持做优秀的商城系统
// +----------------------------------------------------------------------
// | Copyright (c) 2022~2099 http://sparkshop.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\index\service\HomeService;
use app\service\CipherService;
use app\service\OrderService;
use think\facade\View;
use utils\SparkTools;
use think\facade\Db;

class Index extends Base
{
    /**
     * pc商城首页
     */
    public function index(HomeService $homeService)
    {
        $data = $homeService->getHomeData()['data'];
        View::assign($data);

        return View::fetch();
    }

    /**
     * 协议
     */
    public function agreement(HomeService $homeService)
    {
        $type = input('param.type');
        $info = $homeService->getAgreement($type)['data'];

        View::assign([
            'title' => ($type == 1) ? '用户协议' : '隐私协议',
            'info' => $info
        ]);

        return View::fetch();
    }
    /**
     * test
     */
    public function test(CipherService $cipherService)
    {
        $key = '1234123412341234';
        $str = 'sk-abc123abc123abc123';
        $data = $cipherService->key_encrypt($key,$str);
        print_r($data);
        print_r("<br>");
        $data2 = $cipherService->key_decrypt($key,$data);
        print_r($data2);
    }
    /**
     * ordertest
     */
    public function ordertest(CipherService $cipherService,OrderService $orderService)
    {
        // $res = SparkTools::sendSms(['phone' => '15916336162', 'type' => 'com_sms_code']);
        // print_r($res);
        // print_r($orderService->ordersendcard(1,1,1));
    }
    /**
     * update
     */
    public function updategoods()
    {
        // 多分类功能处理
        $goods = Db::name('goods')->select();
        foreach($goods as $v){
            echo "insert into sp_goods_cate_bang(goods_id,cate_id,type)values(".$v['id'].",".$v['cate_id'].",1);<br>";

        }
        
    }
}